// pages/filing/filing.js 
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bbname:'',
    phone:'',
    remark:'',
    pageShow: false,
    submit: false,
  },
  nameinput:function(e){
    var that = this;
    that.setData({
      bbname:e.detail.value
    })
  },
  phoneinput:function(e){
    var that = this;
    that.setData({
      phone: e.detail.value
    })
  },
  remarkinput: function (e) {
    var that = this
    that.setData({
      remark: e.detail.value
    })
  },
  tolist:function(){
    wx.navigateTo({
      url: '/pages/filingList/filingList',
    })
  },
  formsubmit:function(e){
    var that = this;
    if(that.data.submit) return;
    var bbname = that.data.bbname
    var phone = that.data.phone
    var remark = that.data.remark
    var pattern = /^1[3456789]\d{9}$/;
    if (!bbname){
      wx.showToast({
        title: '请输入姓名',
        icon:"none"
      })
    }else if(!pattern.test(phone)){
      wx.showToast({
        title: '请输入正确的手机号',
        icon:"none"
      })
    }else{
      var param = {
        name: bbname,
        phone: phone,
        remark: remark,
      } 
      that.setData({
        submit: !that.data.submit
      })
     app.httpRequest('filing/add', param, 'get', false, function(res){
       wx.showModal({
         title: '友情提示',
         content: res.msg,
         cancelText:'我的报备',
         confirmText:'继续报备',
         success:function(res){
          if (!res.confirm) {
            wx.redirectTo({
              url: '/pages/filingList/filingList',
            })
          }
          that.setData({
            bbname: '',
            phone: '',
            remark: '',
          })
         }
       })
        app.userBehavior(135,'提交了报备信息')
     },'',function(){
      that.setData({
        submit: !that.data.submit
      })
     })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(!wx.getStorageSync('userInfo')){
      wx.navigateTo({
        url: '/pages/welcome/welcome',
      })
      return;
    }
    this.setData({
      pageShow: true,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
})